package com.bdqn.interceptor;

import com.bdqn.pojo.SysUser;
import com.bdqn.utils.Constants;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

public class SysInterceptor extends HandlerInterceptorAdapter {
    private Logger log = Logger.getLogger(SysInterceptor.class);

    public boolean preHandle(HttpServletRequest request , HttpServletResponse response , Object handler) throws Exception{
        log.debug("进入自定义拦截器===》SysInterceptor");
        HttpSession session = request.getSession();

        SysUser sysUser = (SysUser) session.getAttribute(Constants.USER_SESSION);

        if (null == sysUser){
            response.sendRedirect(request.getContextPath()+"/401.jsp");
        }
        return true;
    }
}
